home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: MSVC 1.5 problem using CString class and fstream
- Date: 29 Mar 1996 18:14:20 GMT
- Organization: Netcom
- Message-ID: <4jh99s$1gp@dfw-ixnews6.ix.netcom.com>
- References: <alanshepherd.28.000A4801@online.rednet.co.uk>
- NNTP-Posting-Host: den-co10-17.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Fri Mar 29 12:14:20 PM CST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <alanshepherd.28.000A4801@online.rednet.co.uk>,
- alanshepherd@online.rednet.co.uk says...
- >
- >Hello I am a newby to C++, MSVC and this group so please forgive if this
- >question is naive or has been posted previously.
- >
- >I am having problems in two areas and I suspect they are related. The first
- >occours when I tried to write a simple C++ program using CString types. A
- >simple quickwin example is shown below.
- >
- >#include <iostream.h>
- >#include<afx.h>
- >
- >int CStringfunc( CString&, CString&);
- >
- >CString line = "this is a test of CStringfunc";
- >CString word = "test";
- >
- >void main()
- >{
- > int i = CStringfunc(line,word);
- > cout << " i = " << i << '\n';
- >}
- >.
- >definition of CStringfunc etc.
- >.
- >
- >The code compiles ok but the linker complains that .."mlibcew(delete.cxx) :
- >error l2044: void __far __cdecl operator delete(void __near*) symbol multiply
- >defined" followed by some advice on relinking with /NOE (which also does not
- >work. The same message is repeated for "operator new"
- >
- >this is followed by a list of L2029 errors (unresolved externals) including;
- >GETFILETITLE...DRAGACCEPTFILES...CHOOSECOLOR etc. I have experimented with
- >including various libraries in the link options with no sucess. Any sugestions?
- >
- >The second problem is similar but comes at it from the oposite direction. In
- >this case I wish to use <fstream.h> in my appwizzard generated widows program.
- >I wanted to do some simple text file i/o and thought the fstream class gave
- >better service than the CStdiofile class. The work was just some anciliary
- >bookkeeping and so I didnt want to go the serialise/archive route. I include
- >the header file references for example
- >
- >#include "stdafx.h"
- >#include "appro.h"
- >#include "project.h"
- >#include "logon.h"
- >
- >#include "fstream.h"
- >#include "direct.h"
- >#include "sys\types.h"
- >#include "sys\stat.h"
- >.
- >.
- >Again the code compiles ok but does not link with exactly the same L2044 error
- >on the 'new' and 'delete' operators. I have written a seperate small program
- >using fstream it works fine UNTILL I include <afx.h>. Are these seperate ways
- >of working incompatable or am I doing something wrong? I cant seem to use the
- >CString class outside the application framework or the fstream class within.
- >If anyone else has had similar problems to this or any advice at all I would
- >be greatful to hear from them.
-
- For what it's worth, I've been able to use fstream inside an MFC app
- just fine, but that is MSVC++4.0.
-
- There are two different problems here. The first has to do with
- multiply-defined operators, which I have seen before and worked
- around by excluding linkage of the "msvcrt40" library. That is
- for MSVC4.0, you may have a different version and I don't know
- what works for older VC++.
-
- For the second problem (all the undefined symbols)
- It sounds like the problem originates with the <afx.h> header.
- Many headers, like <ios.h>, define a file-static class variable
- whose sole purpose is to ensure that some subsystem has been
- initialized prior to startup. This is usually done via a lightweight
- reference-counting object:
-
- // Inside someHeader.h:
- // always zero at link-time
- extern static int TheRefCount;
- class ref {
- ref() {
- if (theRefCount==0)
- otherClass::initSubsystem();
- theRefCount++;
- }
- };
- static ref localRef;
-
- These local objects are constructed at program startup, and so they
- ensure that whatever subsystem is iplied by the header has been
- initialized before any application code is executed.
-
- My guess is that when <afx.h> is included, objects of this type are
- instantiated, and that requires that the whole AFX/MFC subsystem be
- linked in. If you don't really need MFC, then don't include this.
- If you need MFC, then link in the MFC libraries.
-
- Hope this helps -- I haven't checked it thoroughly.
-
- john lilley
-
-